package net.mikoo.seals.api.utility;

import javax.servlet.http.HttpServletRequest;

import net.mikoo.seals.model.Party;

public class PartyUtility {

	public static Party getCurrentParty(HttpServletRequest request) {
		if(request == null) {
			throw new IllegalArgumentException("request");
		}
		Object partyObj = request.getAttribute("party");
		if(partyObj == null) {
			throw new RuntimeException("invalid party");
		}
		return (Party)partyObj;
	}
	
	public static Long getCurrentPartyId(HttpServletRequest request) {
		return getCurrentParty(request).getPartyId();
	}
	
	public static Long getCurrentPartyCompanyId(HttpServletRequest request) {
		return getCurrentParty(request).getCompanyId();
	}
	
	public static String getCurrentUserLoginId(HttpServletRequest request) {
		return getCurrentParty(request).getUserLoginId();
	}
	
	public static String getToken(HttpServletRequest request) {
		return request.getHeader("token");
	}
}
